#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
// RDLU
int n, m, N;
inline bool chk(vector<vector<int>> &v, int x, int y) {
    return x >= 1 && x <= m && y >= 1 && y <= n && v[x][y] < 0;
}
void dfs(vector<vector<int>> &v, vector<int> &a, int x, int y, int p, int i) {
    v[x][y] = a[i];
    if (i == N - 1) {
        rep(i, 1, m) rep(j, 1, n) printf("%d%c", v[i][j], j == n ? '\n' : ' ');
        exit(0);
    }
    if (chk(v, x + dx[p], y + dy[p]))
        return dfs(v, a, x + dx[p], y + dy[p], p, i + 1);
    else {  // trans dir
        p = (p + 1) % 4;
        return dfs(v, a, x + dx[p], y + dy[p], p, i + 1);
    }
}
signed main() {
    cin >> N;

    for (int i = sqrt(N);; --i)
        if (N % i == 0) {
            n = i;
            break;
        }

    m = N / n;

    vector<vector<int>> v(m + 1);
    for (vector<int> &vi : v) rep(i, 0, n) vi.push_back(-i);

    vector<int> a(N);
    for (int &x : a) cin >> x;
    sort(a.rbegin(), a.rend());

    dfs(v, a, 1, 1, 0, 0);

    return 0;
}